<template>
  <div>
    <van-checkbox-group v-model="ids">
      <van-checkbox :name="i.id" v-for="i in resourcelist" :key="i">{{ i.name }}

      </van-checkbox>
      <!-- <van-checkbox :name="j.id" v-for="j in i.son" :key="j">{{j.name}}</van-checkbox> -->
    </van-checkbox-group>
    <button @click="add_data">提交</button>
  </div>
</template>

<script>
import axios from "../../http/axios";
export default {
  data() {
    return {
      id: localStorage.getItem("userid"),
      ids: [],
      resourcelist: [],
    };
  },
  methods: {
    getroles() {
      axios("/resourse?userid=" + this.id, "get").then((res) => {
        console.log(res);
        this.ids = res.list;
      });
    },
    getresout() {
      axios("/resourse", "get").then((res) => {
        console.log(res);
        this.resourcelist = res.list;
        this.getroles();
      });
    },
    add_data() {

      axios("/resourse", "post", { userid: this.id, ids: this.ids }).then(
        (res) => {
          console.log(res);
          // window.location.reload()
        }
      );
    },
  },
  mounted() {
    this.getresout();
  },
};
</script>

<style>
</style>